package browser.service;

import browser.dao.UserInfo;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
/**
 * Some utility methods that will be invoked in servlets.
 *
 */
public class MyUtilities{

	/**
	 * Get user information by specifying user id
	 * @param uid User Id
	 * @return User information
	 */
	public static UserInfo getUserInfo(String uid) {

		Configuration cfg = new Configuration();
		SessionFactory sessions = cfg.configure().buildSessionFactory();
		Session session = sessions.openSession();
		Transaction tx = session.beginTransaction();

		String hql = "from UserInfo where userid='" + uid + "'";
		Query q = session.createQuery(hql);
		UserInfo user = (UserInfo) q.list().get(0);
		// UserInfo user = (UserInfo) session.load(UserInfo.class, uid);
		session.close();

		return user;
	}
}
